<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>splice()</title>
	</head>
	<body>
		<p id="old"></p>
		<p id="new">点击按钮添加和删除元素</p>
		<button onclick="my()">点击</button>
		
		<script>
			function my(){
				var old=document.getElementById('old');
				 var mynew=document.getElementById('mynew');
				 
				 var fruits=["Banana","Orange","APPle","Mango"];
				 old.innerHTML=fruits;
				 //在Orange元素之后，添加元素 pear,peach
				 fruits.splice(2,0,"pear","peach");
				 mynew.innerHTML=fruits;
				 
				 //第二个元素之后 删除2个元素
				 fruits.splice(2,2);
				 mynew.innerHTML=fruits;
				 
		
				 
				 
			}
		</script>
	</body>
</html>
